package com.tecnoagrosoft.zafra.control.db;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ClearDB {
	
	private GestorDB gestorDB;
	private GenericManager gM;
	private Context context;
	
	
	
	public ClearDB(Context context) {
		super();
		this.context = context;
	}



	public void clearAll() {

		gestorDB = new GestorDB(context);

		SQLiteDatabase db = gestorDB.getWritableDatabase();
		gM = new GenericManager(db);
		String[] columns = { "_id" };
		Cursor cu = gM.getObjectWhere("sincronizar", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("sincronizar", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("asiento_liquidacion", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("asiento_liquidacion", cu.getInt(cu.getColumnIndex("_id")));
			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("resumen_seguimiento_detalle", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("resumen_seguimiento_detalle", cu.getInt(cu.getColumnIndex("_id")));
			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("resumen_seguimiento", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("resumen_seguimiento", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}
		cu = gM.getObjectWhere("mensaje", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("mensaje", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("gastos_varios", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("gastos_varios", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("trabajo", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("trabajo", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("insumo_detalle", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("insumo_detalle", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("insumo", columns, "_id>7");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("insumo", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("aplicacion", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("aplicacion", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("aplicacion_tipo", columns, "_id>8");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("aplicacion_tipo", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("personal", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("personal", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("cargas_camion", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("cargas_camion", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("seguimiento_de_parcela", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("seguimiento_de_parcela", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("variedad", columns, "_id>200");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("variedad", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("grano", columns, "_id>9");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("grano", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("supervisa", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("supervisa", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}

		cu = gM.getObjectWhere("parcela", columns, "0=0");
		if (cu.moveToFirst()) {
			do {
				gM.deleteObject("parcela", cu.getInt(cu.getColumnIndex("_id")));

			} while (cu.moveToNext());
		}
		


		gM.close();
		db.close();
		gestorDB.close();

	}

}
